package com.wyh.controller.groupfour.admin;

import com.wyh.common.result.Result;
import com.wyh.domain.dto.groupfour.threemeterDTO.GetThreeMeterListDTO;
import com.wyh.domain.dto.groupfour.threemeterDTO.MeterreadingDTO;
import com.wyh.domain.dto.groupfour.threemeterDTO.ThreeMeterDetailDTO;
import com.wyh.domain.dto.groupfour.threemeterDTO.ThreemeterLikeDTO;
import com.wyh.domain.vo.gruopfour.threemeterVO.Development;
import com.wyh.domain.vo.gruopfour.threemeterVO.PageResult;
import com.wyh.domain.vo.gruopfour.threemeterVO.ThreeMeterDetailVO;
import com.wyh.domain.vo.gruopfour.threemeterVO.ThreeMeterTotalVO;
import com.wyh.service.appservice.ThreemeterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.wyh.common.enums.ResultCodeEnum.SYSTEM_ERROR;

/**
 * @author : 是你
 * @since : 2024/6/4 下午1:25
 */
@RestController("threemeter")
@Api(tags = "管家端三表管理")
public class ThreemeterController {

    @Autowired
    private ThreemeterService threemeterService;

    @PostMapping("/getThreeMeters")
    @ApiOperation("三表列表（按楼盘求总和）")
    public Result<PageResult<ThreeMeterTotalVO>> getThreeMeter(@RequestBody @ApiParam("分页查询条件") GetThreeMeterListDTO getThreeMeterListDTO) {
        PageResult<ThreeMeterTotalVO> pageResult = threemeterService.getThreeMeter(getThreeMeterListDTO);
        if (pageResult != null) {
            return Result.success(pageResult);
        }
        return Result.error(SYSTEM_ERROR);
    }

    @PostMapping("/threeMeter")
    @ApiOperation("待抄和已抄的具体三表详细")
    public Result<PageResult<ThreeMeterDetailVO>> threeMeter(@RequestBody @ApiParam("分页查询条件") ThreeMeterDetailDTO threeMeterDetailDTO) {
        PageResult<ThreeMeterDetailVO> pageResult = threemeterService.threeMeter(threeMeterDetailDTO);
        if (pageResult != null) {
            return Result.success(pageResult);
        }
        return Result.error(SYSTEM_ERROR);
    }

    @GetMapping("/getmeter")
    @ApiOperation("待抄表的详细")
    public Result<ThreeMeterDetailVO> getmeter(@RequestParam(value = "threemeterid") @ApiParam(value = "三表id",required = true) Integer threemeterid) {
        ThreeMeterDetailVO threeMeterDetailVO = threemeterService.threeMeterDetail(threemeterid);
        if (threeMeterDetailVO != null) {
            return Result.success(threeMeterDetailVO);
        }
        return Result.error(SYSTEM_ERROR);
    }

    @PostMapping("/meterreading")
    @ApiOperation("抄表")
    public Result meterreading(@RequestBody @Validated @ApiParam("抄表信息") MeterreadingDTO meterreadingDTO) {
        int rows = threemeterService.meterreading(meterreadingDTO);
        if (rows != 0) {
            return Result.success("抄表成功");
        }
        return Result.error(SYSTEM_ERROR);
    }

    @GetMapping("/revokemeterreading")
    @ApiOperation("撤销抄表")
    public Result revokemeterreading(@RequestParam(value = "threeMeterReadingId") @ApiParam(value = "抄表id",required = true) Integer threeMeterReadingId,@RequestParam(value = "developmentid") @ApiParam(value = "楼盘id",required = true) Integer developmentid,@RequestParam(value = "chargingid") @ApiParam(value = "计费表id") Integer chargingid) {
        int rows = threemeterService.revokemeterreading(threeMeterReadingId, developmentid,chargingid);
        if (rows != 0) {
            return Result.success("撤销成功");
        }
        return Result.error(SYSTEM_ERROR);
    }

    @GetMapping("/screen")
    @ApiOperation("筛选条件之一（资源id）")
    public Result<List<Development>> screen(){
        List<Development> list = threemeterService.screen();
        if (list!=null) {
            return Result.success(list);
        }
        return Result.error(SYSTEM_ERROR);
    }


    @PostMapping("/like")
    @ApiOperation("筛选")
    public Result<PageResult<ThreeMeterDetailVO>> like(@RequestBody @ApiParam("模糊查询条件") ThreemeterLikeDTO threemeterLikeDTO) {
        PageResult<ThreeMeterDetailVO> pageResult = threemeterService.like(threemeterLikeDTO);
        if (pageResult != null) {
            return Result.success(pageResult);
        }
        return Result.error(SYSTEM_ERROR);
    }
}


